/****************************************************************
 ** Product  :   HP Subscriber Network Application Policy
 ** Module   :   gr-manager
 ** Date: Apr 10, 2015               
 ** Author: Chen Zhenhua
 ** (C) Copyright 2015, Hewlett-Packard Company, All Rights Reserved.
 ** This software is the proprietary information of HP, Inc.  
 ** Use is subject to license terms.
 *****************************************************************
 ** Description:   
 **   Get SGM monitor cron job status
 **    
 ****************************************************************/
package com.hp.snap.gr.action.impl;

import com.hp.snap.gr.exception.ActionException;
import com.hp.snap.gr.model.jaxb.ActionType;
import com.hp.snap.gr.utils.Constants;
import com.hp.snap.gr.utils.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

/**
 * Get local site and remote site SGM monitor cron job status by executing the "crontab -l" command. If find the
 * "SNAP-GR-Manager.sh MONITOR" return "enable" else "disable", and save the return value into action output.
 * 
 * 
 * There are no parameter can be configured in the action.
 * 
 * Action output: 
 *    Local_monitorSS:  local site monitor cron job status.
 *    Remote_monitorSS: remote site monitor cron job status.
 * 
 * <P>
 * Version: 3.3 <br>
 * Author: Chen Zhenhua Date: Apr 10, 2015
 * 
 * </P>
 * 
 **/
public class GetMonitorStatusActionHandler extends AbstractActionHandler {

    private static String COMMAND = "SNAP-GR-Manager.sh MONITOR";
    private static Logger logger = LoggerFactory.getLogger(GetMonitorStatusActionHandler.class);

    @Override
    public void execute(ActionType action,
                        Map<String, Object> actionPlanInputs,
                        Map<String, Object> actionPlanOutputs) throws ActionException {
        
        String status = Utils.getCronjobStatus(COMMAND);
        if (logger.isDebugEnabled()) {
            logger.debug("The cronjob {} status is:{}", new Object[]{COMMAND, status});
        }

        String remoteStatus = Utils.getRemoteCronjobStatus(COMMAND);
        if (logger.isDebugEnabled()) {
            logger.debug("The remote cronjob {} status is:{}", new Object[]{COMMAND, remoteStatus});
        }

        actionPlanOutputs.put(Constants.STATUS_LOCAL_MONITOR, status);
        actionPlanOutputs.put(Constants.STATUS_REMOTE_MONITOR, remoteStatus);
    }

}
